package com.bichengcao.googlecodejam.qualification2010;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.StringTokenizer;

public class FairWarning {

	static int N;

	public static void main(String[] args) throws IOException {
		Input[] inputs = parseInput("src/com/bichengcao/googlecodejam/qualification2010/B-large.in");
		Output[] outputs = process(inputs);
		writeOutput("src/com/bichengcao/googlecodejam/qualification2010/FairWarning.out", outputs);
	}

	static class Input {
		int n;
		BigInteger[] t;
	}

	static class Output {
		BigInteger y;
	}
	
	private static Input[] parseInput(String filename) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader(filename));
		N = Integer.parseInt(in.readLine());
		Input[] array = new Input[N];

		for (int i = 0; i < N; i++) {
			Input input = array[i] = new Input();
			String line = in.readLine();
			StringTokenizer st = new StringTokenizer(line);
			input.n = Integer.parseInt(st.nextToken());
			input.t = new BigInteger[input.n];
			for (int j = 0; j < input.n; j++) {
				input.t[j] = new BigInteger(st.nextToken());
			}
		}

		in.close();
		return array;
	}

	private static Output[] process(Input[] inputs) {
		Output[] outputs = new Output[N];
		for (int i = 0; i < N; i++) {
			outputs[i] = process(inputs[i]);
		}
		return outputs;
	}

	private static Output process(Input input) {
		Output output = new Output();

		Arrays.sort(input.t);
		BigInteger gcd = BigInteger.ZERO;
		for (int i = 0; i < input.n - 1; i++) {
			BigInteger d = input.t[i + 1].subtract(input.t[i]);
			if (!d.equals(BigInteger.ZERO)) {
				if (gcd.equals(BigInteger.ZERO)) {
					gcd = d;
				} else {
					gcd = d.gcd(gcd);
				}
			}
		}
		output.y = gcd.subtract(input.t[0].subtract(BigInteger.ONE).mod(gcd).add(BigInteger.ONE));
		
		return output;
	}

	private static void writeOutput(String filename, Output[] outputs) throws IOException {
		PrintWriter out = new PrintWriter(new FileWriter(filename));
		for (int i = 0; i < N; i++) {
			Output output = outputs[i];
			out.println("Case #" + (i + 1) + ": " + output.y.toString());
		}
		out.close();
	}

}
